package com.gomoku.controller;



import com.gomoku.common.exception.BusinessException;
import com.gomoku.common.exception.ErrorCode;
import com.gomoku.common.result.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

/**
 * Hello World 测试控制器
 * 用于验证后端服务是否正常运行
 * 
 * @author gomoku
 * @version 1.0.0
 * @since 2024-01-01
 */
@RestController
@RequestMapping("/api")
public class HelloController {

    /**
     * 简单的Hello接口
     * 
     * @return 欢迎信息
     */
    @GetMapping("/hello")
    public Result<Map<String, Object>> hello() {
        Map<String, Object> data = new HashMap<>();
        data.put("message", "Hello, 五子棋在线对战平台！");
        data.put("timestamp", LocalDateTime.now());
        data.put("service", "gomoku-backend");
        data.put("version", "1.0.0");
        return Result.success("欢迎使用五子棋在线对战平台！", data);
    }

    /**
     * 健康检查接口
     * 
     * @return 服务状态信息
     */
    @GetMapping("/health")
    public Result<Map<String, Object>> health() {
        Map<String, Object> data = new HashMap<>();
        data.put("status", "UP");
        data.put("service", "gomoku-backend");
        data.put("timestamp", LocalDateTime.now());
        data.put("uptime", "running");
        return Result.success("服务运行正常", data);
    }

    /**
     * 测试异常处理接口
     * 
     * @param type 异常类型
     * @return 测试结果
     */
    @GetMapping("/test-exception")
    public Result<String> testException(@RequestParam(defaultValue = "business") String type) {
        switch (type) {
            case "business":
                throw new BusinessException(ErrorCode.USER_NOT_FOUND, "用户不存在");
            case "validation":
                throw new BusinessException(ErrorCode.PARAM_ERROR, "参数错误");
            case "system":
                throw new BusinessException(ErrorCode.SYSTEM_ERROR, "系统错误");
            default:
                return Result.success("测试完成");
        }
    }
}
